package com.link2room.quintesson.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.quintesson.dto.param.manager.TaobaoXroomtypeManagerParamDto;
import com.link2room.quintesson.dto.result.manager.TaobaoXroomtypeDto;
import com.link2room.quintesson.facade.ITaobaoXroomtypeFacadeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by VegetaKo on 2017/1/12.
 */
@RestController
@RequestMapping("/manager/TaobaoXroomtypes")
public class TaobaoXroomtypeManagerController {

    @Resource
    private ITaobaoXroomtypeFacadeService taobaoXroomtypeFacadeService;

    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto taobaoXroomtypeList(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam(value = "currentPage" ,required = false) Integer currentPage,
            @RequestParam(value = "pageSize" ,required = false) Integer pageSize
    ) throws Exception {
        TaobaoXroomtypeManagerParamDto taobaoXroomtypeManagerParamDto=new TaobaoXroomtypeManagerParamDto();
        taobaoXroomtypeManagerParamDto.setLhotelCode(lhotelCode);
        taobaoXroomtypeManagerParamDto.setCurrentPage(currentPage);
        taobaoXroomtypeManagerParamDto.setPageSize(pageSize);
        QueryResult<TaobaoXroomtypeDto> taobaoXroomtypeResult = taobaoXroomtypeFacadeService.listTaobaoXroomtype(taobaoXroomtypeManagerParamDto);
        BaseResultDto<TaobaoXroomtypeDto> baseResultDto=new BaseResultDto<>();
        baseResultDto.setResultCode(0);
        baseResultDto.setQueryResult(taobaoXroomtypeResult);
        return baseResultDto;
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public BaseResultDto taobaoXroomtype(
            @PathVariable Long id
    ) throws Exception {
        TaobaoXroomtypeManagerParamDto taobaoXroomtypeManagerParamDto=new TaobaoXroomtypeManagerParamDto();
        taobaoXroomtypeManagerParamDto.setId(id);
        TaobaoXroomtypeDto taobaoXroomtypeDto = taobaoXroomtypeFacadeService.findTaobaoXroomtype(taobaoXroomtypeManagerParamDto);
        BaseResultDto<TaobaoXroomtypeDto> baseResultDto=new BaseResultDto<>();
        baseResultDto.setResultCode(0);
        baseResultDto.setResultInfo(taobaoXroomtypeDto);
        return baseResultDto;
    }

    @RequestMapping(method= RequestMethod.PUT)
    public BaseResultDto updateTaobaoXroomtypeList(
            @RequestBody TaobaoXroomtypeManagerParamDto taobaoXroomtypeManagerParamDto
    )throws Exception{
        List<TaobaoXroomtypeDto> taobaoXroomtypeDtoList = taobaoXroomtypeFacadeService.saveOrUpdateTaobaoXroomtypeList(taobaoXroomtypeManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setListToQueryResult(taobaoXroomtypeDtoList);
        return l2rRs;
    }

    @RequestMapping(value = "/TaobaoXroomtype",method= RequestMethod.PUT)
    public BaseResultDto updateTaobaoXroomtype(
            @RequestBody TaobaoXroomtypeManagerParamDto taobaoXroomtypeManagerParamDto
    )throws Exception{
        TaobaoXroomtypeDto taobaoXroomtypeDto=taobaoXroomtypeFacadeService.saveOrUpdateTaobaoXroomtype(taobaoXroomtypeManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(taobaoXroomtypeDto);
        return l2rRs;
    }
}
